package dao

import (
	"fmt"
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/util/gconv"
)

var T_hzfgw_record_gw = t_hzfgw_record_gw{}

type t_hzfgw_record_gw struct {
}

func (a *t_hzfgw_record_gw) GetLastRid(addr string) (rid uint64) {
	rid = 0
	db := g.DB(g.Cfg().GetString("custom.db_name"))
	re, err := db.GetOne(fmt.Sprintf("SELECT MAX(rid) as rid FROM `t_hzfgw_record_gw` WHERE  addr='%s'", addr))
	if err != nil {
		rid = 0
	} else {
		if re != nil {
			rid = gconv.Uint64(re.Map()["rid"])
		}
	}
	return rid
}

func (a *t_hzfgw_record_gw) SaveList(data interface{}) (isOk bool, err error) {
	db := g.DB(g.Cfg().GetString("custom.db_name"))
	_, err = db.Model("t_hzfgw_record_gw").Data(data).Save()
	if err != nil {
		return false, err
	} else {
		return true, nil
	}
}

func (a *t_hzfgw_record_gw) Delete(where ...string) (isOk bool, err error) {
	db := g.DB(g.Cfg().GetString("custom.db_name"))
	model := db.Model("t_hzfgw_record_gw")
	if len(where) == 0 {
		_, err = model.Delete()
	} else {
		_, err = model.Delete(where)
	}
	if err != nil {
		return false, err
	} else {
		return true, nil
	}
}
